package org.activequant.core.domainmodel.account.util;

import java.util.ArrayList;
import java.util.List;

import org.activequant.core.domainmodel.account.BalanceBook;
import org.activequant.core.domainmodel.account.BalanceEntry;
import org.activequant.core.types.TimeStamp;
import org.activequant.core.types.Tuple;

/**
 * This class gathers utilities surrounding the balance book.<br>
 * <br>
 * <b>History:</b><br>
 * - [28.02.2009] Created (Ulrich Staudinger)<br>
 * 
 * @author Ulrich Staudinger
 * 
 */
public class BalanceBookUtils {

	/**
	 * this helper method converts the balance book entries into a list of
	 * cumulated equity curve tuples, which is very handy for charting the
	 * equity curve.<br/>
	 * returns a List&lt;Tuple&lt;TimeStamp, Double&gt;&gt; holding timeStamp-cumulativeSum pairs calculated from each
	 * BalanceEntry of the given aBook(BalanceBook)
	 * @param aBook
	 * @return a list of tuples of timestamp and doubles
	 */

	public static List<Tuple<TimeStamp, Double>> getEquityCurveTuples(BalanceBook aBook) {
		List<Tuple<TimeStamp, Double>> myRet = new ArrayList<Tuple<TimeStamp, Double>>();
		Double mySum = 0.0;
		for (BalanceEntry myEntry : aBook.getBalanceEntries()) {
			mySum += myEntry.getValue();
			Tuple<TimeStamp, Double> myTuple = new Tuple<TimeStamp, Double>(myEntry.getTimeStamp(), mySum);
			myRet.add(myTuple);
		}
		return myRet;
	}

}
